package com.sihai.ehr.utils;

import com.sihai.core.LimitedList;
import com.sihai.ehr.model.biz.SalaryStatistics;
import com.sihai.ehr.model.biz.SalaryStatisticsDetail;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * Created by IntelliJ IDEA.
 * User: Wang.Yi
 * Date: 2013-3-7
 * Time: 10:45:42
 * To change this template use File | Settings | File Templates.
 */
public class SalaryStatisticsUtil {

    public static Map<String,Float>  getTotalAmount(LimitedList<SalaryStatistics> salaryStatisticses){
        if(salaryStatisticses==null || salaryStatisticses.size()<=0)
            return null;
        Map<String,Float> map=new HashMap<String,Float>();
        Iterator it=salaryStatisticses.iterator();
        while(it.hasNext()){
             SalaryStatistics sta=(SalaryStatistics)it.next();
             Set<SalaryStatisticsDetail> set=sta.getDetails();
             Float total=0F;
             Iterator subit=set.iterator();
             while(subit.hasNext()){
                 SalaryStatisticsDetail detail=(SalaryStatisticsDetail)subit.next();
                 if(detail.getStructType().toString().equals("subsidy")){
                     total+=detail.getSchemeSalary();
                 }else{
                     total-=detail.getSchemeSalary();
                 }
             }
            map.put(String.valueOf(sta.getId()),total);
        }
        return map;
    }
}
